package com.linkage.jz.bankruptcy.fragment.Project;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.google.gson.Gson;
import com.linkage.jz.bankruptcy.BankruptcyApp;
import com.linkage.jz.bankruptcy.Consts;
import com.linkage.jz.bankruptcy.R;
import com.linkage.jz.bankruptcy.activity.Project.CreateProjectDetailThreeActivity;
import com.linkage.jz.bankruptcy.activity.Project.ProDetailActivity;
import com.linkage.jz.bankruptcy.activity.Project.ProZQDetailActivity;
import com.linkage.jz.bankruptcy.activity.Project.ZQSetTimeActivity;
import com.linkage.jz.bankruptcy.activity.Project.ZQUser.ZQUserDetailActivity;
import com.linkage.jz.bankruptcy.bean.MyProInfo;
import com.linkage.jz.bankruptcy.bean.ProZQInfo;
import com.linkage.jz.bankruptcy.bean.ProZQInfoAuth;
import com.linkage.jz.bankruptcy.bean.ZQUserDetailBaseInfo;
import com.linkage.jz.bankruptcy.net.ToastUtil;
import com.linkage.jz.bankruptcy.utils.SPUtils;
import com.linkage.jz.bankruptcy.utils.SignUtil;
import com.linkage.jz.bankruptcy.utils.Utils;
import com.linkage.jz.bankruptcy.widget.BaseMessage;
import com.linkage.jz.bankruptcy.widget.CakeView;
import com.linkage.jz.bankruptcy.widget.PageView;
import com.linkage.jz.bankruptcy.widget.PublicNoticeDialog;
import com.linkage.jz.bankruptcy.widget.ShapeLoadingDialog;
import com.linkage.jz.bankruptcy.widget.ZQTimeNoticeDialog;
import com.linkage.seapeak.activity.project.SearchDeclarationInfoActivity;
import com.linkage.seapeak.utils.CommonUtils;

import org.greenrobot.eventbus.EventBus;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static com.linkage.jz.bankruptcy.utils.Utils.StringToLeng;

/**
 * @author FT
 * @time 2016-07-18 16:49
 */

// JUMP 
public class ProZQFragment extends Fragment {
    RecyclerView mRecyclerView;
    private ShapeLoadingDialog shapeLoadingDialog ;
    private Context context;
    private int mPage;
    public static final String MERCHANT_DETAILS_PAGE = "MERCHANT_DETAILS_PAGE";
    private DemoAdapter mAdapter;
//    private LinearLayout ll_addflow;
    private String mProID;
    List<ProZQInfo> mData;
    private Boolean editflag;
    private int subType = 1;
    private static MyProInfo myProInfo;

    private ProZQInfoAuth auth;

    public static ProZQFragment newInstance(int page, String proID, MyProInfo info) {
        Bundle args = new Bundle();
        args.putInt(MERCHANT_DETAILS_PAGE, page);
        myProInfo= info;
        args.putString("proID", proID);
        ProZQFragment tripFragment = new ProZQFragment();
        tripFragment.setArguments(args);
        return tripFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPage = getArguments().getInt(MERCHANT_DETAILS_PAGE);
        mProID  = getArguments().getString("proID");
        context = getActivity().getApplicationContext();
        shapeLoadingDialog = new ShapeLoadingDialog(getActivity());
        setData();
    }

    @Override
    public void onResume() {
        super.onResume();
//        ProDetailActivity parentActivity = (ProDetailActivity) getActivity();
//        parentActivity.showLoading();
        getData();

    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_pro_detailpro_zq, container, false);
        mRecyclerView = (RecyclerView) view.findViewById(R.id.mRecyclerView);
//        ll_addflow =(LinearLayout) view.findViewById(R.id.ll_addflow);
//        ll_addflow.setOnClickListener(new View.OnClickListener() {
//
//            @Override
//            public void onClick(View v) {
//                ProNodeInfo info = new ProNodeInfo();
//                info.setModelCode("");
//                CreateProFlowActivity.start(getActivity(),info,mProID);
//            }
//        });
        mData = new ArrayList<ProZQInfo>();
                initAdapter(mData);
        getData();
        editflag = false;
        return view;
    }

    private void setData(){
//        mFoodData = new ArrayList<>();
//        for(int i=0; i<5;i++){
//            mFoodData.add("美食"+i);
//        }

    }
    private ZQTimeNoticeDialog  zqTimeNoticeDialog;
    /**
     * 设置RecyclerView属性
     */
    private void initAdapter(List<ProZQInfo> data) {
//        mRecyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter = new DemoAdapter(data);
        mAdapter.openLoadAnimation();
        mRecyclerView.setAdapter(mAdapter);//设置adapter


        //设置item点击事件
        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {

                Button bt1=(Button) adapter.getViewByPosition(mRecyclerView, position, R.id.id_mid_Btn01);
                Button bt2=(Button) adapter.getViewByPosition(mRecyclerView, position, R.id.id_mid_Btn02);
                Button bt3=(Button) adapter.getViewByPosition(mRecyclerView, position, R.id.id_mid_Btn03);
                ProZQInfo proZQInfo1 = mData.get(position);
                switch (view.getId()) {

                    case R.id.btn_save:
                    case R.id.btn_edit:


                    if(auth !=null )
                    {
                        if(!auth.isSetDeclarationTime())
                        {
                            ToastUtil.showShort("您没有权限操作。");
                            return;
                        }
                    }
                        long lst_time = 0l;
                        String st_time = "";
                        String et_time = "";
                        if (proZQInfo1.getClaimFilingStartTime() != null) {
                            lst_time = StringToLeng(proZQInfo1.getClaimFilingStartTime());
                            st_time = Utils.timeStamp2Date(lst_time * 1000, "yyyy-MM-dd HH:mm");
                        }
                        long led_time = 0l;
                        if (proZQInfo1.getClaimFilingEndTime() != null) {
                            led_time = StringToLeng(proZQInfo1.getClaimFilingEndTime());
                            et_time = Utils.timeStamp2Date(led_time * 1000, "yyyy-MM-dd HH:mm");
                        }


                        ZQSetTimeActivity.start(getActivity(), mProID, st_time, et_time);
                        break;
                    case R.id.btn_send:

                        if(auth !=null )
                        {
                            if(!auth.isSetDeclarationTime())
                            {
                                ToastUtil.showShort("您没有权限操作。");
                                return;
                            }
                        }
                          zqTimeNoticeDialog = new ZQTimeNoticeDialog(getActivity(), new View.OnClickListener() {
                            @Override
                            public void onClick( View view ) {
                                String  sendStatus = "";
                                if (view.getId() == R.id.btn_chancel_notice) {//暂存
                                    sendStatus = "1";
                                    zqTimeNoticeDialog.dismiss();
                                } else if (view.getId() == R.id.ll_close) {
                                    if (zqTimeNoticeDialog != null && zqTimeNoticeDialog.isShowing())
                                        zqTimeNoticeDialog.dismiss();

                                    return;
                                } else if (view.getId() == R.id.btn_save) {//生成


                                    if(!zqTimeNoticeDialog.send_msg.isChecked() && !zqTimeNoticeDialog.send_phone.isChecked())
                                    {
                                        Toast.makeText(getActivity(),
                                                "请选择发送方式",Toast.LENGTH_SHORT).show();
                                        return;
                                    }
                                    zqTimeNoticeDialog.dismiss();
                                    String smsflag = zqTimeNoticeDialog.send_msg.isChecked()?"true":"false";
                                    String msgflag = zqTimeNoticeDialog.send_phone.isChecked()?"true":"false";
                                    saveData(smsflag,msgflag);
                                } else {
                                    zqTimeNoticeDialog.dismiss();

                                }


                            }
                          }, 0);
                        zqTimeNoticeDialog.show();

                        break;
                    case R.id.id_mid_Btn01:
                        subType = 1;


                        bt1.setBackgroundResource(R.drawable.about_b_corner_btn);
                        bt2.setBackgroundResource(R.drawable.about_g_corner_btn);
                        bt3.setBackgroundResource(R.drawable.about_g_corner_btn);

                        getSubData();
                        bt1.setTextColor(getResources().getColor(R.color.white));
                        bt2.setTextColor(getResources().getColor(R.color.text_secondary_color));
                        bt3.setTextColor(getResources().getColor(R.color.text_secondary_color));
                        break;

                    case R.id.id_mid_Btn02:
                        subType= 2;

                        bt1.setBackgroundResource(R.drawable.about_g_corner_btn);
                        bt2.setBackgroundResource(R.drawable.about_b_corner_btn);
                        bt3.setBackgroundResource(R.drawable.about_g_corner_btn);
                        bt1.setTextColor(getResources().getColor(R.color.text_secondary_color));
                        bt2.setTextColor(getResources().getColor(R.color.white));
                        bt3.setTextColor(getResources().getColor(R.color.text_secondary_color));
                        getSubData();
                        break;
                    case R.id.id_mid_Btn03:
                        subType=3;
                        bt1.setBackgroundResource(R.drawable.about_g_corner_btn);
                        bt2.setBackgroundResource(R.drawable.about_g_corner_btn);
                        bt3.setBackgroundResource(R.drawable.about_b_corner_btn);
                        bt1.setTextColor(getResources().getColor(R.color.text_secondary_color));
                        bt2.setTextColor(getResources().getColor(R.color.text_secondary_color));
                        bt3.setTextColor(getResources().getColor(R.color.white));
                        getSubData();
                        break;
                    case R.id.ll_zq_row:
//                        ProZQDetailActivity.start(getActivity(), mProID);
//                        Intent intent = new Intent(getActivity(), ProZQDetailActivity.class);
//                        intent.putExtra("info",new Gson().toJson(myProInfo));
//                         getActivity().startActivity(intent);
//                        sss
                        ProZQInfo proZQInfo = mData.get(position);
                        if (proZQInfo != null) {
                            Intent intent = new Intent(getActivity(), ZQUserDetailActivity.class);
                            intent.putExtra("creditorId", proZQInfo.getCreditorId());
                            intent.putExtra("proid", mProID);
                            intent.putExtra("page", 1);
                            getActivity().startActivity(intent);
                        }
                        break;

                    case R.id.ly_search://搜索申报信息
                        Intent intentSearch = new Intent(getActivity(), SearchDeclarationInfoActivity.class);
                        intentSearch.putExtra("projectId",mProID);
                        getActivity().startActivity(intentSearch);
                        break;
                }
            }
        });

    }
    /**
     * adapter
     */
    class DemoAdapter extends BaseMultiItemQuickAdapter<ProZQInfo,BaseViewHolder> {
        public DemoAdapter(List<ProZQInfo> data) {
            super(data);
            addItemType(1, R.layout.fragment_pro_detailpro_zq_item_nodata);
            addItemType(2, R.layout.fragment_pro_detailpro_zq_item_settime);
            addItemType(3, R.layout.fragment_pro_detailpro_zq_item_top);
            addItemType(4, R.layout.fragment_pro_detailpro_zq_item_middle);
            addItemType(5, R.layout.fragment_pro_detailpro_zq_item_bottom);
            addItemType(6, R.layout.zq_empty_layout);
            addItemType(101, R.layout.fragment_pro_detailpro_zq_item_nodata);
            addItemType(0xfffffe6c, R.layout.zq_empty_layout);
        }

        @Override
        protected void convert(BaseViewHolder helper, ProZQInfo item) {
            switch (helper.getItemViewType()) {
                case 0xfffffe6c:
                    break;
                case 101:
                    break;

                case 1:
                    helper.addOnClickListener(R.id.btn_save);
                    if(auth !=null )
                    {
                        if(!auth.isSetDeclarationTime())
                        {
                            helper.setVisible(R.id.btn_save,false);
//                            ToastUtil.showShort("您没有权限操作。");
                            return;
                        }
                    }
//                    helper.setText(R.id.tv_item_smart_refresh, item.getName());
//                    GlideApp.with(mContext).load(item.getBgPicture()).into((ImageView) helper.getView(R.id.iv_item_smart_refresh));
                    break;
                case 2:

                    if(!auth.isSetDeclarationTime())
                    {
                        helper.setVisible(R.id.btn_edit,false);
                        helper.setVisible(R.id.btn_send,false);
//                            ToastUtil.showShort("您没有权限操作。");
                        return;
                    }

                    helper.addOnClickListener(R.id.btn_edit);
                    helper.addOnClickListener(R.id.btn_send);
                    try {
                        if (!"".equalsIgnoreCase(item.getClaimFilingStartTime()) && !"".equalsIgnoreCase(item.getClaimFilingEndTime())) {
                            long lst_time = StringToLeng(item.getClaimFilingStartTime());
                            long led_time = StringToLeng(item.getClaimFilingEndTime());
                            ;
                            String st_time = Utils.timeStamp2Date(lst_time*1000, "yyyy-MM-dd HH:mm");


                            String et_time = Utils.timeStamp2Date(led_time*1000, "yyyy-MM-dd HH:mm");
                            if (led_time == 0) {
                                et_time = "待定";
                            }

                            helper.setText(R.id.tv_zq_time, "申报期限：" + st_time + " -- " + et_time);
                        }
                    }catch (Exception ex)
                    {
                        helper.setText(R.id.tv_zq_time, "申报期限：" );
                        ex.printStackTrace();
                    }
                    break;
                case 3:



                    LayoutInflater inflater = LayoutInflater.from(getActivity());

                    PageView mPageView = (PageView) helper.getView(R.id.pageview);
                    if(mPageView.getPageCount()>0)
                    {
                        return;
                    }
//                    mPageView.removeAllPages();
                     CakeView cv;
                    CakeView cv_r;
                     List<BaseMessage> mList;

                    LinearLayout view = (LinearLayout) inflater.inflate(R.layout.fragment_pro_detailpro_zq_item_top_subleft, null);
                    mPageView.addPage(view);
                    LinearLayout view1 = (LinearLayout) inflater.inflate(R.layout.fragment_pro_detailpro_zq_item_top_subright, null);
                    mPageView.addPage(view1);


                    float f_top_left1 = 0.0f;
                    float f_top_left2 =  0.0f;
                    float f_top_left3 =  0.0f;
                    float f_top_left4 =  0.0f;

                    float f_top_right1 =  0.0f;
                    float f_top_right2 = 0.0f;
                    float f_top_right3 =  0.0f;

//
//                    float f_top_left1 = 10.0f;
//                    float f_top_left2 =  20.0f;
//                    float f_top_left3 =  30.0f;
//                    float f_top_left4 =  40.0f;
//
//                    float f_top_right1 =  2.0f;
//                    float f_top_right2 = 20.0f;
//                    float f_top_right3 =  30.0f;

                    try {
                        f_top_left1 = Float.parseFloat(item.getKindTaxMoney());
                        f_top_left2 = Float.parseFloat(item.getKindGuaranteeMoney());
                        f_top_left3 = Float.parseFloat(item.getKindOtherMoney());
                        f_top_left4 = Float.parseFloat(item.getKindOrdinaryMoney());

                        f_top_right1 = Float.parseFloat(item.getConfirmedMoney());
                        f_top_right2 = Float.parseFloat(item.getDisconfirmationMoney());
                        f_top_right3 = Float.parseFloat(item.getUndeterminedMoney());

                    }catch (Exception ex){
                        ex.printStackTrace();
                    }


                    helper.setText(R.id.top_left1, CommonUtils.resetMoney(item.getKindTaxMoney())+"");
                    helper.setText(R.id.top_left2, CommonUtils.resetMoney(item.getKindGuaranteeMoney())+"");
                    helper.setText(R.id.top_left3, CommonUtils.resetMoney(item.getKindOtherMoney())+"");
                    helper.setText(R.id.top_left4, CommonUtils.resetMoney(item.getKindOrdinaryMoney())+"");

                    helper.setText(R.id.top_right1, CommonUtils.resetMoney(item.getConfirmedMoney())+"");
                    helper.setText(R.id.top_right2, CommonUtils.resetMoney(item.getDisconfirmationMoney())+"");
                    helper.setText(R.id.top_right3, CommonUtils.resetMoney(item.getUndeterminedMoney())+"");

//                    helper.setText(R.id.top_right1, "111");
//                    helper.setText(R.id.top_right2, "22");
//                    helper.setText(R.id.top_right3, "33");

                    cv = (CakeView) helper.getView(R.id.cv);
                    mList = new ArrayList<BaseMessage>();

                    BaseMessage mes = new BaseMessage();
                    mes.setPercent(f_top_left1);
                    mes.setContent("");
                    mes.setColor(Color.parseColor("#87B0C9"));
                    mList.add(mes);

                    BaseMessage message = new BaseMessage();
                    message.setPercent(f_top_left2);
                    message.setContent("");
                    ;
                    message.setColor(Color.parseColor("#FF9C5D"));
                    mList.add(message);

                    BaseMessage mes0 = new BaseMessage();
                    mes0.setPercent(f_top_left3);
                    mes0.setContent("ֹ");
                    mes0.setColor(Color.parseColor("#F3DB57"));
                    mList.add(mes0);

                    BaseMessage mes1 = new BaseMessage();
                    mes1.setPercent(f_top_left4);
                    mes1.setContent("");
                    mes1.setColor(Color.parseColor("#EBE9DC"));
                    mList.add(mes1);
                    cv.setCakeData(mList);


                    cv_r = (CakeView) helper.getView(R.id.cv2);
                    mList = new ArrayList<BaseMessage>();

                    BaseMessage mes_r = new BaseMessage();
                    mes_r.setPercent(f_top_right1);
//                    mes_r.setPercent(10);
                    mes_r.setContent("");
                    mes_r.setColor(Color.parseColor("#FF9C5D"));
                    mList.add(mes_r);

                    BaseMessage mes_r2 = new BaseMessage();
                    mes_r2.setPercent(f_top_right2);
//                    mes_r2.setPercent(30);
                    mes_r2.setContent("");
                    mes_r2.setColor(Color.parseColor("#87B0C9"));
                    mList.add(mes_r2);


                    BaseMessage mes_r3 = new BaseMessage();
                    mes_r3.setPercent(f_top_right3);
//                    mes_r3.setPercent(20);
                    mes_r3.setContent("");
                    mes_r3.setColor(Color.parseColor("#EBE9DC"));
                    mList.add(mes_r3);
                    cv_r.setCakeData(mList);


                    break;
                case 4:


                    if(!auth.isWaitDoAndSearch())
                    {

//                            ToastUtil.showShort("您没有权限操作。");
                        helper.setGone(R.id.ll_middle,false);
                        return;
                    }
                    helper.addOnClickListener(R.id.id_mid_Btn01);
                    helper.addOnClickListener(R.id.id_mid_Btn02);
                    helper.addOnClickListener(R.id.id_mid_Btn03);
                    helper.addOnClickListener(R.id.ly_search);
                    String time_zq = "";
                    try {
                        if (!"".equalsIgnoreCase(item.getClaimFilingStartTime()) && !"".equalsIgnoreCase(item.getClaimFilingEndTime())) {
                            long lst_time = StringToLeng(item.getClaimFilingStartTime());
                            long led_time = StringToLeng(item.getClaimFilingEndTime());
                            ;
                            String st_time = Utils.timeStamp2Date(lst_time*1000, "yyyy-MM-dd HH:mm");
                            String et_time = Utils.timeStamp2Date(led_time*1000, "yyyy-MM-dd HH:mm");
                            if (led_time == 0) {
                                et_time = "待定";
                            }
                            helper.setText(R.id.zq_time, "申报期限：" + st_time + " -- " + et_time);
                        }
                    }catch (Exception ex)
                    {
                        helper.setText(R.id.zq_time, "申报期限：" );
                        ex.printStackTrace();
                    }

                    break;
                case 5:
                    if(!auth.isWaitDoAndSearch())
                    {

//                            ToastUtil.showShort("您没有权限操作。");
                        helper.setGone(R.id.ll_zq_row,false);
                        return;
                    }
                    helper.addOnClickListener(R.id.ll_zq_row);
                    if (item == null) {
                        return;
                    }
                    helper.setText(R.id.tv_zq_title, item.getTitle());

                    String str_time = Utils.timeStamp2Date(Long.parseLong(item.getTime())*1000,"yyyy-MM-dd HH:mm:ss");

                    if ("2".equalsIgnoreCase(item.getOverdue()))
                    {
                        helper.setVisible(R.id.tv_zq_status,true);
                    }else{
                        helper.setGone(R.id.tv_zq_status,false);
                    }

                    helper.setText(R.id.tv_zq_time, str_time);
                     if("1".equalsIgnoreCase(item.getStatus())) {


                        if("3".equalsIgnoreCase(item.getRecondType()))
                        {
                            helper.setText(R.id.tv_zq_jg, "已回复");
                        }else{
                            helper.setText(R.id.tv_zq_jg, "已审核");
                        }
                    }else{
                         if("3".equalsIgnoreCase(item.getRecondType()))
                         {
                             helper.setText(R.id.tv_zq_jg, "未回复");
                         }else{
                             helper.setText(R.id.tv_zq_jg, "待审核");
                         }
                     }
                    break;
                case 6:
                    break;
                default:
                    break;
            }
        }
    }

    public void getData()
    {

        if(BankruptcyApp.tokeninfo == null|| BankruptcyApp.tokeninfo.getToken() == null)
        {
            List<ProZQInfo> list = new ArrayList<ProZQInfo>();
            ProZQInfo info = new ProZQInfo();
            info.setItemType(101);
            list.add(info);
            mData.clear();
            mData.addAll(list);
            return;

        }
//        ll_nodata.setVisibility(View.GONE);
//        shapeLoadingDialog.setLoadingText("加载中...");
//        shapeLoadingDialog.setCanceledOnTouchOutside(false);
//        shapeLoadingDialog.show();
        OkHttpClient okHttpClient = new OkHttpClient();
//        HashMap<String, String> params = new HashMap<String, String>();
        Random random = new Random();
        String rom = random.nextLong()+"";
        String timestamp =System.currentTimeMillis()+"";
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken","");
        String userId = SPUtils.getInstance(Consts.SPNAME).getString("userId","");

        RequestBody requestBody = new FormBody.Builder()
                .add("appid","1000000001")
                .add("nonce",rom)
                .add("timestamp", timestamp)
                .add("userToken", userToken)
                .add("token", BankruptcyApp.tokeninfo.getToken())
//                .add("token", "")

                .add("projectId",mProID)


                .build();

        String url = Consts.WEBURL_RIGHTSGEN;
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {


                String str = response.body().string();
                boolean subshow=true;
                try{
                    JSONObject object = new JSONObject(str);
//                    mData.clear();
//                    if(object.optInt("code") == 0)
//                    {
                    JSONObject jsondata = object.getJSONObject("data");
                    String typejson = jsondata.optString("type");
                    auth = new Gson().fromJson(object.optJSONObject("data").optString("auth").toString(), ProZQInfoAuth.class);

//                    ProZQInfo info = new ProZQInfo();
                    List<ProZQInfo> list = new ArrayList<ProZQInfo>();
                    if("notSetTime".equalsIgnoreCase(typejson))
                    {
                        ProZQInfo info = new ProZQInfo();
                        info.setItemType(1);
//                        info.setAuth(auth);
                        list.add(info);
                    }else if("notSendNotice".equalsIgnoreCase(typejson)){
                        ProZQInfo info = new ProZQInfo();
                        try {
                            JSONObject jsondatatime = jsondata.getJSONObject("time");
                            if (jsondatatime != null) {
                                info.setClaimFilingStartTime(jsondatatime.getString("claimFilingStartTime"));
                                info.setClaimFilingEndTime(jsondatatime.getString("claimFilingEndTime"));
                            }
                        }catch (Exception ex)
                        {
                            info.setClaimFilingStartTime("0");
                            info.setClaimFilingEndTime("0");
                            ex.printStackTrace();
                        }
                        info.setItemType(2);
//                        info.setAuth(auth);
                        list.add(info);
                    }else{
                        ProZQInfo info = new ProZQInfo();
//                        info.setAuth(auth);
                        try {
                            JSONObject jsondatatime = jsondata.getJSONObject("time");
                            if (jsondatatime != null) {
                                info.setClaimFilingStartTime(jsondatatime.getString("claimFilingStartTime"));
                                info.setClaimFilingEndTime(jsondatatime.getString("claimFilingEndTime"));
                            }
                        }catch (Exception ex)
                        {
                            info.setClaimFilingStartTime("0");
                            info.setClaimFilingEndTime("0");
                            ex.printStackTrace();
                        }
                        info.setItemType(3);
//                        list.add(info);
//                        try {
//                            JSONObject jsondatatime = object.getJSONObject("time");
//                            if (jsondatatime != null) {
//                                info.setClaimFilingStartTime(jsondatatime.getString("claimFilingStartTime"));
//                                info.setClaimFilingEndTime(jsondatatime.getString("claimFilingEndTime"));
//                            }
//                        }catch (Exception ex)
//                        {
//                            info.setClaimFilingStartTime("0");
//                            info.setClaimFilingEndTime("0");
//                            ex.printStackTrace();
//                        }
                        JSONObject jsongeneral = jsondata.getJSONObject("general");
                        JSONObject jsondecMoney = jsongeneral.getJSONObject("decMoney");
                        JSONObject jsonreviewMoney = jsongeneral.getJSONObject("reviewMoney");
//                        JSONObject jsontime = jsongeneral.getJSONObject("time");

                        info.setKindTaxMoney(jsondecMoney.optString("kindTaxMoney"));
                        info.setKindGuaranteeMoney(jsondecMoney.optString("kindGuaranteeMoney"));
                        info.setKindOtherMoney(jsondecMoney.optString("kindOtherMoney"));
                        info.setKindOrdinaryMoney(jsondecMoney.optString("kindOrdinaryMoney"));

                        info.setConfirmedMoney(jsonreviewMoney.optString("confirmedMoney"));
                        info.setDisconfirmationMoney(jsonreviewMoney.optString("disconfirmationMoney"));
                        info.setUndeterminedMoney(jsonreviewMoney.optString("undeterminedMoney"));

                        list.add(info);

                        ProZQInfo info2 = new ProZQInfo();
//                        info2.getAuth().setCreditorReview(false);
                        info2.setItemType(4);

                        try {
                            JSONObject jsondatatime = jsondata.getJSONObject("time");
                            if (jsondatatime != null) {
                                info2.setClaimFilingStartTime(jsondatatime.getString("claimFilingStartTime"));
                                info2.setClaimFilingEndTime(jsondatatime.getString("claimFilingEndTime"));
                            }
                        }catch (Exception ex)
                        {
                            info2.setClaimFilingStartTime("0");
                            info2.setClaimFilingEndTime("0");
                            ex.printStackTrace();
                        }
                        list.add(info2);


                    }





//                    final Boolean flag = subshow;

                    if(mData.size()>0)
                    {


                    }else{
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mData.clear();
                                mData.addAll(list);
                            }

                        });
                    }

                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            //更新UI
                            getSubData();
                            mAdapter.notifyDataSetChanged();

                        }

                    });

                }catch (Exception ex)
                {
                    ex.printStackTrace();

                    try {
                        List<ProZQInfo> list = new ArrayList<ProZQInfo>();
                        ProZQInfo info = new ProZQInfo();
                        info.setItemType(101);
                        list.add(info);
                        mData.clear();
                        mData.addAll(list);
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
                                mAdapter.notifyDataSetChanged();

                            }

                        });
                    }catch (Exception exce)
                    {
                        exce.printStackTrace();
                    }
                }
            }
        });
    }




    public void getSubData()
    {

        Boolean subshow =true;
        if(auth!=null) {
//                            auth.setCreditorReview(false);
            subshow = auth.isWaitDoAndSearch();
        }

        if(!subshow)
        {
            return;
        }

        if(BankruptcyApp.tokeninfo == null|| BankruptcyApp.tokeninfo.getToken() == null)
        {
            List<ProZQInfo> list = new ArrayList<ProZQInfo>();
            ProZQInfo info = new ProZQInfo();
            info.setItemType(101);
            list.add(info);
            mData.clear();
            mData.addAll(list);
            return;
        }
//        ll_nodata.setVisibility(View.GONE);
//        shapeLoadingDialog.setLoadingText("加载中...");
//        shapeLoadingDialog.setCanceledOnTouchOutside(false);
//        shapeLoadingDialog.show();
        OkHttpClient okHttpClient = new OkHttpClient();
//        HashMap<String, String> params = new HashMap<String, String>();
        Random random = new Random();
        String rom = random.nextLong()+"";
        String timestamp =System.currentTimeMillis()+"";
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken","");
        String userId = SPUtils.getInstance(Consts.SPNAME).getString("userId","");


        RequestBody requestBody = new FormBody.Builder()
                .add("appid","1000000001")
                .add("nonce",rom)
                .add("timestamp", timestamp)
                .add("userToken", userToken)
                .add("token", BankruptcyApp.tokeninfo.getToken())
//                .add("token", "")
                .add("projectId",mProID)
                .add("type",subType+"")
                .build();

        String url = Consts.WEBURL_PENDINGRECOND;
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
                List<ProZQInfo> list = new ArrayList<ProZQInfo>();
                ProZQInfo info = new ProZQInfo();
                info.setItemType(101);
                list.add(info);
                mData.clear();
                mData.addAll(list);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {


                String str = response.body().string();
//                if(Consts.ISDEBUG)
//                {

//                }
                try{
                    JSONObject object = new JSONObject(str);
//                    mData.clear();
//                    if(object.optInt("code") == 0)
//                    {
                    JSONObject jsondata = object.getJSONObject("data");
                    JSONArray jsonAry = jsondata.getJSONArray("list");

                    List<ProZQInfo> list = new ArrayList<ProZQInfo>();

                    ProZQInfo info_tmp1 = mData.get(0);
                    ProZQInfo info_tmp2 = mData.get(1);
                    mData.clear();
                    mData.add(info_tmp1);
                    mData.add(info_tmp2);

                    for(int i=0;i<jsonAry.length();i++)
                    {
                        JSONObject jsonObj= jsonAry.getJSONObject(i);
                        ProZQInfo info = new ProZQInfo();
                        info.setItemType(5);
                        info.setTime(jsonObj.optString("time"));
                        info.setStatus(jsonObj.optString("status"));
                        info.setOverdue(jsonObj.optString("overdue"));
                        info.setOnlineStatus(jsonObj.optString("onlineStatus"));
                        info.setRecondType(subType+"");

                        info.setProjectId(jsonObj.optString("projectId"));
                        info.setCreditorRightsId(jsonObj.optString("creditorRightsId"));
                        info.setCrRevObjeId(jsonObj.optString("crRevObjeId"));

                        info.setCrRevObjeId(jsonObj.optString("crRevObjeId"));
                        info.setCreditorId(jsonObj.optString("creditorId"));
                        info.setTitle(jsonObj.optString("title"));
//                        list.add(info);
                        mData.add(info);
                    }

                    if (jsonAry == null || jsonAry.length() == 0) {
                        ProZQInfo info = new ProZQInfo();
                        info.setItemType(6);
                        mData.add(info);
                    }



//                    mData.addAll(list);




                    if(mData.size()>0)
                    {

                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI

                            }

                        });
                    }else{
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
//                                ll_nodata.setVisibility(View.VISIBLE);
//                                mDataRv.setVisibility(View.GONE);
                            }

                        });
                    }
                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            //更新UI
                            mAdapter.notifyDataSetChanged();

                        }

                    });

                }catch (Exception ex)
                {
                    List<ProZQInfo> list = new ArrayList<ProZQInfo>();
                    ProZQInfo info = new ProZQInfo();
                    info.setItemType(101);
                    list.add(info);
                    mData.clear();
                    mData.addAll(list);
                    ex.printStackTrace();
                }
            }
        });
    }


    public void saveData(String smsflag ,String msgflag)
    {



        String strStime = "";
        String strEtime = "";


        strStime = Utils.Date2timeStamp(strStime,"yyyy-MM-dd HH:mm");
        strEtime = Utils.Date2timeStamp(strEtime,"yyyy-MM-dd HH:mm");


        if(BankruptcyApp.tokeninfo == null|| BankruptcyApp.tokeninfo.getToken() == null)
        {
//            getToken();
            return;
        }
        shapeLoadingDialog.setLoadingText("提交信息中...");
        shapeLoadingDialog.setCanceledOnTouchOutside(false);
        shapeLoadingDialog.show();

        OkHttpClient okHttpClient = new OkHttpClient();
        HashMap<String, String> params = new HashMap<String, String>();
        Random random = new Random();
        String rom = random.nextLong()+"";
        String timestamp =System.currentTimeMillis()+"";

        String str_switch_show = "";


        String sign = SignUtil.createSign(Consts.APPKEY,params);
        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken","");

        RequestBody requestBody = new FormBody.Builder()
                .add("appid","1000000001")
                .add("nonce",rom)
                .add("timestamp", timestamp)
                .add("token", BankruptcyApp.tokeninfo.getToken())
                .add("userToken", userToken)

                .add("sms", smsflag)
                .add("msg", msgflag)
                .add("projectId", mProID)



                .build();

        String url = Consts.WEBURL_SENDDECLARANOTICE;

        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();

        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
//                Log.d(TAG, "onFailure: " + e.getMessage());
                shapeLoadingDialog.dismiss();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
//                Log.d(TAG, response.protocol() + " " +response.code() + " " + response.message());
                Headers headers = response.headers();


                shapeLoadingDialog.dismiss();
                String str = response.body().string();
                try{
                    JSONObject object = new JSONObject(str);
                    if(object.optInt("code") == 0)
                    {

                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
                                Toast.makeText(getActivity(),
                                        "提交成功",Toast.LENGTH_SHORT).show();
                                getData();
                                EventBus.getDefault().post(Consts.EVENTFLOW);
//                                finish();

                            }

                        });
                    }else{
                        getActivity().runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                //更新UI
                                Toast.makeText(getActivity(),
                                        "提交失败",Toast.LENGTH_SHORT).show();


                            }

                        });
                    }

                    str = "";
                }catch (Exception ex)
                {

                    ex.printStackTrace();
                }
            }
        });


    }

//    public void feedBackKnow(String changeid)
//    {
//
//
//
//
//        if(BankruptcyApp.tokeninfo == null|| BankruptcyApp.tokeninfo.getToken() == null)
//        {
////            getToken();
//            return;
//        }
//        shapeLoadingDialog.setLoadingText("提交信息中...");
//        shapeLoadingDialog.setCanceledOnTouchOutside(false);
//        shapeLoadingDialog.show();
//
//        OkHttpClient okHttpClient = new OkHttpClient();
//        HashMap<String, String> params = new HashMap<String, String>();
//        Random random = new Random();
//        String rom = random.nextLong()+"";
//        String timestamp =System.currentTimeMillis()+"";
//
//
//
//        String sign = SignUtil.createSign(Consts.APPKEY,params);
//        String userToken = SPUtils.getInstance(Consts.SPNAME).getString("userToken","");
//
//        RequestBody requestBody = new FormBody.Builder()
//                .add("appid","1000000001")
//                .add("nonce",rom)
//                .add("timestamp", timestamp)
//                .add("token", BankruptcyApp.tokeninfo.getToken())
//                .add("userToken", userToken)
//
//                .add("changeId", changeid)
//                .add("projectId", mProID)
//
//
//
//                .build();
//
//        String url = Consts.WEBURL_SENDDECLARANOTICE;
//
//        Request request = new Request.Builder()
//                .url(url)
//                .post(requestBody)
//                .build();
//
//        okHttpClient.newCall(request).enqueue(new Callback() {
//            @Override
//            public void onFailure(Call call, IOException e) {
////                Log.d(TAG, "onFailure: " + e.getMessage());
//                shapeLoadingDialog.dismiss();
//            }
//
//            @Override
//            public void onResponse(Call call, Response response) throws IOException {
////                Log.d(TAG, response.protocol() + " " +response.code() + " " + response.message());
//                Headers headers = response.headers();
//
//
//                shapeLoadingDialog.dismiss();
//                String str = response.body().string();
//                try{
//                    JSONObject object = new JSONObject(str);
//                    if(object.optInt("code") == 0)
//                    {
//
//                        getActivity().runOnUiThread(new Runnable() {
//
//                            @Override
//                            public void run() {
//                                //更新UI
//                                Toast.makeText(getActivity(),
//                                        "提交成功",Toast.LENGTH_SHORT).show();
//                                getData();
//                                EventBus.getDefault().post(Consts.EVENTFLOW);
////                                finish();
//
//                            }
//
//                        });
//                    }else{
//                        getActivity().runOnUiThread(new Runnable() {
//
//                            @Override
//                            public void run() {
//                                //更新UI
//                                Toast.makeText(getActivity(),
//                                        "提交失败",Toast.LENGTH_SHORT).show();
//
//
//                            }
//
//                        });
//                    }
//
//                    str = "";
//                }catch (Exception ex)
//                {
//
//                    ex.printStackTrace();
//                }
//            }
//        });
//
//
//    }

}
